package com.ylxn.six;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.ylxn.utils.BuiltinExchangeType;
import com.ylxn.utils.RabbitMqUtils;

/**
 * @author cenghaile
 * @version 1.0
 * 2021/7/1 6:56 下午
 **/
public class ReciveLogsDirect02 {
    /**
     * 交换机名
     */
    public static final String EXCHANGE_NAME ="direct_log";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();
        //声名一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT.getType());
        //声名一个队列
        channel.queueDeclare("disk",false,false,false,null);
        //队列交换机捆绑
        channel.queueBind("disk",EXCHANGE_NAME,"error");

        DeliverCallback deliverCallback = (consumerTag, message)->{
            System.out.println("disk发送消息成功" + new String(message.getBody(),"UTF-8"));
        };
        CancelCallback cancelCallback = (consumerTag)->{
            System.out.println("disk发送消息失败" + consumerTag);
        };
        //消费
        channel.basicConsume("disk",deliverCallback,cancelCallback);
    }
}
